﻿using System.Collections.Generic;

namespace KillBill.Common.Security
{
    public class ActiveSessions
    {
        private readonly Dictionary<string, Session> _activeSessions;
        public ActiveSessions()
        {
            _activeSessions = new Dictionary<string, Session>();
        }
        public Session GetSession(string sessionId)
        {
            return (_activeSessions.ContainsKey(sessionId)) ? _activeSessions[sessionId] : null;
        }
        public bool StartSession(Session session)
        {
            if (!_activeSessions.ContainsKey(session.SessionId))
            {
                _activeSessions.Add(session.SessionId, session);
                return true;
            }
            return false;
        }
        public void CloseSession(string sessionId)
        {
            if (sessionId != null && _activeSessions.ContainsKey(sessionId)) _activeSessions.Remove(sessionId);
        }
    }
}
